package com.xiaoniu.lib_keleim.utils;

import com.google.gson.JsonSyntaxException;
import com.xiaoniu.lib_keleim.IMClient;
import com.xiaoniu.lib_keleim.pojo.vos.BaseMessage;

public class MessageParseUtil {

    public static BaseMessage parseMessage(BaseMessage mBaseMessage, String messageJson) {
        try {
            Class clazz = IMClient.Companion.getManager().getMsgTypes().get(mBaseMessage.msgType);
            if (clazz==null) {
                LogUtils.e("消息解析失败 "+ mBaseMessage.msgType + " 线程 "+Thread.currentThread().getName());
                LogUtils.d("parseMessage "+messageJson);
                return mBaseMessage;
            }
            BaseMessage message = (BaseMessage) GsonUtil.fromJson(messageJson, clazz);
            //EventBusUtil.post(message);
            LogUtils.d("转发聊天室消息 "+messageJson);

            return message;
        } catch (JsonSyntaxException e) {
            e.printStackTrace();
        }

        return mBaseMessage;
    }
}
